package cc.geguo.data;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import org.apache.struts2.ServletActionContext;

import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import sun.plugin2.message.GetAppletMessage;

/**
 * Created by 13687 on 2017/1/8.
 */
public class DataAction extends ActionSupport {
	@Override
	public String execute() throws Exception {
//		1. 请求数据封装
//		2. 处理service 拿到结果
//		3. 数据保存到域中
//		ServletContext applicaton = ServletActionContext.getServletContext();
//		HttpServletRequest request = ServletActionContext.getRequest();
//		HttpSession session = request.getSession();

//		直接在action中操作servlet中的方法
//		request.setAttribute("requets_data","request_data");
//		session.setAttribute("session_data","session_data");
//		applicaton.setAttribute("application_data","application_data");

//===============================以下方式不需要引入servlet包==============
//		拿到表示request/application/session 的map对象
		ActionContext ac = ActionContext.getContext();
		Map<String, Object> req = ac.getContextMap();
		Map<String, Object> session = ac.getSession();
		Map<String, Object> application = ac.getApplication();

		req.put("requets_data","request_data");
		session.put("session_data","session_data");
		application.put("application_data","application_data");

		return SUCCESS;
	}
}
